﻿using System;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;
using Wei8808Cms.Utility;
using Wei8808Cms.WebSite.UI;

namespace Wei8808Cms.WebSite.admin.Administrator
{
    public partial class AddAdministratorInfoForm : BasicPage
    {
        private readonly AdministratorBLL _bll = new AdministratorBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                chkLoginLevel("addAdministrator");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            var model = new AdministratorInfo();
            string userLevel = string.Empty;
            string userName = txtUserName.Text.Trim();
            string userPwd = txtUserPwd.Text.Trim();
            string readName = txtReadName.Text.Trim();
            string userEmail = txtUserEmail.Text.Trim();
            int userType = Convert.ToInt32(rblUserType.SelectedValue);
            int isLock = Convert.ToInt32(rblIsLock.SelectedValue);
            if (_bll.Exists(userName))
            {
                JscriptMsg(350, 230, "错误提示", "<b>出现错误了！</b>用户名已存在，请输入别的管理帐号吧！", "", "Error");
                return;
            }
            if (userType > 1)
            {
                userLevel = "," + Request.Form["cbLevel"].Trim() + ",";
            }
            model.Id = GuidHelper.GetGuid();
            model.UserName = userName;
            model.UserPwd = userPwd;
            model.ReadName = readName;
            model.UserEmail = userEmail;
            model.UserType = userType;
            model.IsLock = isLock;
            model.UserLevel = userLevel;
            model.CreateUser = "李波";
            model.CreateTime = DateTime.Now;
            _bll.Add(model);
            JscriptPrint("添加系统用户成功！", "AdministratorMasterForm.aspx", "Success");
        }
    }
}